package com.web.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class GlobalThreadPool {

    // 创建全局线程池
    private static final ExecutorService threadPool = Executors.newCachedThreadPool();

    // 提供一个方法来提交任务到线程池
    public static void execute(Runnable task) {
        threadPool.execute(task);
    }

    // 示例：提交任务
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            execute(() -> {
                System.out.println("Thread Name: " + Thread.currentThread().getName() + " is executing task ");
            });
        }
    }
}
